<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<c:set var="path" value="${pageContext.request.contextPath }" />
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="renderer" content="webkit">
<meta http-equiv="Cache-Control" content="no-siteapp" />
<title>主页</title>
<link rel="shortcut icon" href="favicon.ico">
<!--[if lt IE 8]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->

<!-- 本框架基本脚本和样式 -->
<script type="text/javascript"
	src="${path }/resource/js/jquery-2.1.4.min.js"></script>
<script type="text/javascript"
	src="${path }/resource/js/systools/MBase.js"></script>
<script type="text/javascript" src="${path }/resource/js/content.min.js"></script>

<!-- 界面单独引入的其他样式和脚本 -->
<link rel="stylesheet"
	href="${path }/resource/plugin/zTree/zTreeStyle/zTreeStyle.css"
	type="text/css">
<script type="text/javascript"
	src="${path }/resource/plugin/zTree/jquery.ztree.core-3.5.min.js"></script>


</head>

<body class="gray-bg">
	<nav class="huiNav">
		<%@include file="project-nav.jsp"%>需求管理 <a
			class="btn btn-info  btn-sm pull-right"
			href="javascript:location.replace(location.href);" title="刷新"><i
			class="fa fa-refresh"></i></a>
	</nav>
	<div class="wrapper wrapper-content  animated fadeInRight">
		<div class="row">
			<div class="col-sm-4">
				<div class="ibox float-e-margins">
					<div class="ibox-title">
						<h5>需求列表</h5>
						<br>
						<form class="form-horizontal dataform " id="dataformQuery">
							<div class="form-group">
								<div class="  col-sm-5">
									<select onchange="initFunctionList()" style="width: 100px" class="form-control autoFull"
										name="type" 
										data-url="${path}/admin/dataDictionary/showDataDictionary"
										data-filed="name" data-value="name" data-param="{type:'需求类型'}"
										 >
										<option value="">--请选择需求类型--</option>
									</select>
								</div>
								<div class="  col-sm-5">
									<select   onchange="initFunctionList()" style="width: 100px" class="form-control autoFull "
										name="status" 
										data-url="${path}/admin/dataDictionary/showDataDictionary"
										data-filed="name" data-value="name" data-param="{type:'需求状态'}"
										 >
										<option value="">--请选择状态--</option>
									</select>
								</div>
							</div>
							<a class="f-r text-success " onclick="openForm()"><i
								class="fa fa-plus c-success"></i> 添加需求</a>
						</form>
						<div class="pull-right "></div>
					</div>
					<div id="treeDemo" class="ibox-content ztree"
						style="min-height: 400px"></div>
				</div>
			</div>
			<div class="col-sm-8">
				<div class="ibox float-e-margins">
					<div class="ibox-title">
						<h5>编辑需求</h5>
						<div class="ibox-tools"></div>
					</div>
					<div class="ibox-content" style="min-height: 400px">
						<form style="display: none;" class="form-horizontal dataform "
							id="dataform">
							<input type="hidden" name="id" id="cateId">
							<div class="form-group">
								<label class="col-sm-2 control-label">父级类型</label>
								<div class="  col-sm-4">
									<select class="form-control " size="1" name="parentId"
										id="parentId">
										<option value="-10" selected="selected">一级类型</option>
									</select>
								</div>
								<label class="col-sm-2 control-label">需求名称</label>

								<div class="  col-sm-4">
									<input id="name" type="text" name="name" class="form-control "
										datatype="*1-50" nullmsg="类型名称不能为空">
									<div class="Validform_checktip"></div>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label">需求类型</label>
								<div class="col-sm-4">
									<select class="form-control autoFull" name="type" id="type"
										dataType="*1-20" ignore="ignore"
										data-url="${path}/admin/dataDictionary/showDataDictionary"
										data-filed="name" data-value="name" data-param="{type:'需求类型'}"
										data-def="${obj.type}">
										<option value="">--请选择需求类型--</option>
									</select>
								</div>
								<label class="col-sm-2 control-label  ">优先级：</label>
								<div class="  col-sm-4">
									<select class="form-control autoFull" name="priority"
										dataType="*1-20" ignore="ignore" id="priority"
										data-url="${path}/admin/dataDictionary/showDataDictionary"
										data-filed="name" data-value="name"
										data-param="{type:'需求优先级'}" data-def="${obj.priority}">
										<option value="">--请选择优先级--</option>
									</select>
								</div>
								<div class="Validform_checktip"></div>
							</div>

							<div class="form-group">
								<label class="col-sm-2 control-label">需求状态</label>
								<div class="col-sm-4">
									<select class="form-control autoFull " name="status"
										dataType="*1-20" ignore="ignore" id="status"
										data-url="${path}/admin/dataDictionary/showDataDictionary"
										data-filed="name" data-value="name" data-param="{type:'需求状态'}"
										data-def="${obj.status}">
										<option value="">--请选择状态--</option>
									</select>
								</div>
								<label class="col-sm-2 control-label  ">备注：</label>
								<div class="  col-sm-4">
									<input type="text" name="remark" id="remark"
										value="${obj.remark }" class="form-control radius">
									<div class="Validform_checktip"></div>
								</div>
								<div class="Validform_checktip"></div>
							</div>

							<div class="form-group">
								<div class="col-sm-12 text-center">
									<a class="btn btn-success radius" onclick="updateFunction()">保存</a>
									<a class="btn btn-danger  radius" onclick="delFunction()">删除</a>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
	<script type="text/javascript">
		var Huiform = null;
		$(".select2").select2();
		//下拉框自动赋值
		MTools.autoFullSelect();
		$(function() {
			initFunctionList();
			Huiform = MValidform.validform("#dataform")
		});

		/**
		 * 初始化类型列表
		 */
		function initFunctionSelected(id) {
			$
					.AjaxProxy({
						a : false,
						c : false
					})
					.invoke(
							"${path}/admin/interfaceCate/all?projId=${projId}",
							function(loj) {
								$("#parentId")
										.createSelectTree(
												loj.attr("result").rows,
												{
													append : false,
													defaultValue : id,
													defaultHtml : '<option value="-10" selected="selected">一级类型</option>'
												});
							});

		}

		function initFunctionList() {
			var zNodes = new Array();
			var query=MForm.toJson($("#dataformQuery"));
			$.AjaxProxy({data:query}).invoke(
					"${path}/admin/interfaceCate/all?projId=${projId}",
					function(loj) {
						for (var i = 0; i < loj.getRowCount(); i++) {
							zNodes[i] = createNode(loj.getString(i, "id"), loj
									.getString(i, "parentId"), loj.getString(i,
									"name")
									+ " | "
									+ loj.getString(i, "type")
									+ " | "
									+ loj.getString(i, "status"));
						}
						initTree(zNodes);
					});
		}

		function updateFunction() {
			var myForm = MForm.initForm({
				invokeUrl : "${path}/admin/interfaceCate/addOrModify",
				afterSubmit : function() {
					initFunctionList();
				},
			});
			myForm.submit();
		}

		function initTree(zNodes) {
			var setting = {
				view : {
					dblClickExpand : false,
					showLine : false,
					selectedMulti : false
				},
				data : {
					simpleData : {
						enable : true,
						idKey : "id",
						pIdKey : "pId",
						rootPId : ""
					}
				},
				callback : {
					onClick : zTreeOnClick
				}
			};
			$.fn.zTree.init($("#treeDemo"), setting, zNodes);
		}

		// 点击加载节点信息
		function zTreeOnClick(event, treeId, treeNode) {
			$("#dataform").show();
			Huiform.resetForm();
			$.AjaxProxy({
				p : {
					id : treeNode.id
				},
				a : false,
				c : true
			}).invoke("${path}/admin/interfaceCate/findById", function(loj) {
				// 初始化类型基本信息
				initFunctionSelected(loj.getString(0, "parentId"));
				$("#cateId").val(loj.getString(0, "id"));
				$("#name").val(loj.getString(0, "name"));

				$("#priority").val(loj.getString(0, "priority"));
				$("#status").val(loj.getString(0, "status"));
				$("#type").val(loj.getString(0, "type"));
				$("#remark").val(loj.getString(0, "remark"));
			});
		};

		function createNode(id, parentId, name) {
			var o = new Object();
			o.id = id;
			o.pId = parentId;
			o.name = name;
			o.open = true;
			return o;
		}
		function showIcon() {
			layer.open({
				type : 2,
				title : "选择图标",
				area : [ '80%', '80%' ],
				fix : true, // 不固定
				maxmin : true,
				content : '${path}/common/redirect/icons'
			});
		}

		function delFunction() {
			var id = $("#cateId").val();
			if (id != null && id != '') {
				layer.confirm('删除类型时会删除该类型的所有子类型！', {
					icon : 3,
					title : '提示'
				}, function(index) {
					layer.close(index);
					var id = $("#cateId").val();
					$.AjaxProxy({
						p : {
							keys : id
						}
					}).invoke("${path}/admin/interfaceCate/del", function(loj) {
						layer.alert('删除成功！', {
							icon : 1
						}, function(index) {
							$("#dataform").hide();
							layer.close(index);
							initFunctionList();
						});
						return false;
					});
				});
			} else {
				layer.alert("请先选中要删除的类型！");
			}
		}

		function openForm() {
			console
					.info('${path}/admin/interfaceCate/editForm?projId=${projId}')
			layer
					.open({
						type : 2,
						title : "新增类型",
						area : [ MUI.SIZE_L, '400px' ],
						content : '${path}/admin/interfaceCate/editForm?projId=${projId}'
					});
		}
	</script>

</body>
</html>